package dpda;

import pda.PDAConfiguration;
import pda.Stack;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

/**
 * @author haoly
 * @title DPDADesign
 * @date 2025/4/21 14:36
 * @description TODO
 */
public class DPDADesign <T>{
    private final T startState;

    private final Character bottomCharacter;

    private final Set<T> acceptStates;

    private final DPDARulebook<T> rulebook;

    public DPDADesign(T startState, Character bottomCharacter, Set<T> acceptStates, DPDARulebook<T> rulebook) {
        this.startState = startState;
        this.bottomCharacter = bottomCharacter;
        this.acceptStates = new HashSet<>(acceptStates);
        this.rulebook = rulebook;
    }

    public DPDA<T> toDpda(){
        Stack<Character> startStack = new Stack<>(Arrays.asList('$'));
        PDAConfiguration<T> startConfiguration = new PDAConfiguration<>(startState, startStack);
        return new DPDA<>(startConfiguration, acceptStates, rulebook);
    }

    public Boolean accepts(String s){
        DPDA<T> dpda = toDpda();
        dpda.readString(s);
        return dpda.accetpting();
    }
}
